#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QList>
#include <QStringList>
#include <QTimer>
#include <QCanBusDevice>
#include <QCanBusFrame>
#include <QByteArray>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:

    enum
    {
      REPLY_NONE        = 0x00,
      REPLY_HANDSHAKE   = 0x55,
      REPLY_ACK         = 0x41,
      REPLY_NAK         = 0x4E,
      REPLY_BREAK_UP    = 0x42,
      REPLY_EOT         = 0x45,
      SEND_BREAK_UP     = 0x42424242,
      SEND_EOT          = 0x45454545,
    };

    Ui::MainWindow *ui;
    QStringList interfaceName;
    QTimer *MonitoringPortAndStart_Timer;
    QCanBusDevice *CanDev;
    quint8 SendFlag;


    QString QByteArrayToString(QByteArray buf);
    bool WriteFrame(QByteArray data,quint16 stID);
    int WaitInfoFrame(quint8 flag,int timeout);
    bool WriteInfoFrame(quint32 value);
    bool SendHandShack(quint32 filesize);
    void wait(int msec);

private slots:
    void MonitoringPortAndStart_Timer_Handler(void);
    void CanError(QCanBusDevice::CanBusError);
    void FreshHandler(void);


    void on_btn_connect_clicked();
    void on_btn_fresh_clicked();
    void on_tbtn_Select_clicked();
    void on_btn_dowmload_clicked();

signals:
    void FreshApp(void);

};
#endif // MAINWINDOW_H
